<template>
  <div id="app">
      <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>

<script>

export default {
  name: 'App',
  provide () {
    return {
      reload: this.reload
    }
  },
  data () {
    return {
      isRouterAlive: true
    }
  },
  created () {
    window.addEventListener('beforeunload', () => {
      localStorage.setItem('Assessment', JSON.stringify(this.$store.state))
    })
    localStorage.getItem('Assessment') && this.$store.replaceState(Object.assign(this.$store.state, JSON.parse(localStorage.getItem('Assessment'))))
  },
  methods: {
    reload () {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    }
  }
}
</script>
<style>
  html,body{
    margin: 0;
    padding: 0;
  }
</style>
